//
//  FMDB_TGM_Category.m
//  TravelGuideMdd
//
//  Created by BigPolarBear on 13-5-20.
//  Copyright (c) 2013年 mafengwo.com. All rights reserved.
//

#import "FMDB_TGM_Category.h"
#import "DBConst.h"

@implementation FMResultSet(TGM)

/** 根据结果里的json字段，初始化基于BaseItem的类型 */
-(NSArray*)arrayOfItemClass:(Class)itemClass
{
    if (![itemClass isSubclassOfClass:[BaseItem class]]) {
        // todo 异常，必须传入BaseItem的子类
        return nil;
    }
    
    NSMutableArray* array = [NSMutableArray arrayWithCapacity:0];
    while ([self next]) {
        NSString* json = [self stringForColumn:kTableColumn_base_c_json];
        id dic = [json jsonObject];
        if (dic && [dic isKindOfClass:[NSDictionary class]]) {
            id item = [[itemClass alloc]initWithDictionary:dic];
            [array addObject:item];
        }
    }
    return array;
}

@end
